package router

import (
	"context"
	"github.com/gogf/gf/v2/net/ghttp"
	"server/internal/controller/websocket_controller"
	"server/internal/library/websocket"
)

func Websocket(ctx context.Context, s *ghttp.Server) {
	// 连接处理
	s.BindHandler("/websocket", websocket.ServeWs)

	// 启动 websocket 监听
	websocket.Start()

	// 注册 websocket 消息路由处理器
	websocket.RegisterRouter(websocket.EventHandlerRouters{
		"ping":              websocket_controller.CLogin.Ping,              //心跳
		"logout":            websocket_controller.CLogin.Logout,            //退出连接
		"forceClientLogout": websocket_controller.CLogin.ForceClientLogout, //强制客戶端退出
		"monitorInfo":       websocket_controller.CMonitor.MonitorInfo,     //监控信息
		"hubBaseInfo":       websocket_controller.CMonitor.HubBaseInfo,     //系统运行信息
		"processInfo":       websocket_controller.CMonitor.ProcessInfo,     //系统运行信息
	})
}
